﻿using static CyberU;
using static CyberU.UI;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class MouseDown : MonoBehaviour, IPointerDownHandler
{
    public UnityEvent onLeftMousePressed = new UnityEvent();
    public UnityEvent<PointerEventData> onLeftMousePressedWithData = new UnityEvent<PointerEventData>();

    public UnityEvent onRightMousePressed = new UnityEvent();
    public UnityEvent<PointerEventData> onRightMousePressedWithData = new UnityEvent<PointerEventData>();
    public UnityEvent onPressed = new UnityEvent();
    public UnityEvent<PointerEventData> onPressedWithData = new UnityEvent<PointerEventData>();

    public void Add(UnityAction action) => onPressed.AddListener(action);
    public void Add(UnityAction<PointerEventData> action) => onPressedWithData.AddListener(action);

    public void AddLeft(UnityAction action) => onLeftMousePressed.AddListener(action);
    public void AddLeft(UnityAction<PointerEventData> action) => onLeftMousePressedWithData.AddListener(action);

    public void AddRight(UnityAction action) => onRightMousePressed.AddListener(action);
    public void AddRight(UnityAction<PointerEventData> action) => onRightMousePressedWithData.AddListener(action);

    public void OnPointerDown(PointerEventData eventData)
    {
        if (eventData.button == PointerEventData.InputButton.Left)
        {
            onLeftMousePressed.Invoke();
            onLeftMousePressedWithData.Invoke(eventData);
        }
        else if (eventData.button == PointerEventData.InputButton.Right)
        {
            onRightMousePressed.Invoke();
            onRightMousePressedWithData.Invoke(eventData);
        }
    }
}